#ifndef TCPSERVERSENDER_H
#define TCPSERVERSENDER_H

#include <vector>
#include <iostream>
#include <boost/asio.hpp>
#include <memory>

class TcpServerSender
{
public:
    TcpServerSender(const std::string &listenIP, unsigned short listenPort);
    ~TcpServerSender();
    void start();
    bool send(std::vector<uint8_t> buffer);
    bool send(const std::stringstream &stream);
    void stop();
    bool dispose();

private:
    void removeClient(std::shared_ptr<boost::asio::ip::tcp::socket> socket);
    void startAccept();

private:
    boost::asio::ip::tcp::endpoint endpoint_;
    std::unique_ptr<boost::asio::io_context> io_context_;
    std::unique_ptr<boost::asio::ip::tcp::acceptor> acceptor_;
    std::vector<std::shared_ptr<boost::asio::ip::tcp::socket>> clients_;

    std::mutex client_mutex_;
    std::thread io_thread_;
    bool running_{false};
};

#endif // TCPSERVERSENDER_H